<!--本页面由uniapp切片工具生成，uni-app切片-可视化设计工具(一套代码编译到7个平台iOS、Android、H5、小程序)，软件下载地址：http://www.ymznkf.com/new_view_669.htm -->
<template>
	<view class="YmContent">
		<!-- 	<view style="display: flex;justify-content: space-between;">
					<view v-for="item in huodong"
						style=" border: 1px solid;padding: 2%;display: flex;justify-content: space-between;">
						<view>
							{{item.name}}
						</view>
					</view>
				</view> -->
				<view style="margin:8% auto;width: 90%;">
		<view  style="text-align: center;font-weight: bold;" class="voucher_center__47">充值金额</view>
		
	
		<view  style="margin-top: 8%;" >
			<uni-data-checkbox mode="tag" max="1" multiple  :map="map" v-model="value" :localdata="huodong"
				@change="change"></uni-data-checkbox>
		</view>
		<view style="text-align: center;color: #999;font-size: 10px;">
			(充值金额无有效期限，不可退还，不可转让）
		</view>
		</view>
		<view class="voucher_center__1">
			<text decode="true" class="voucher_center__47">自定义金额</text>

			<view class="voucher_center__48">

				<text decode="true" class="voucher_center__49">￥</text>
				<input type="digit" v-model="money" class="money" @input="nom" />

			</view>

			<button @click="btSubmit_21_click()" class="btSubmit">确认支付
			</button>
			<text decode="true" class="voucher_center__22">充值须知</text>
			<text decode="true" class="voucher_center__23">1.充值成功后，充值金额将不可退还，请在充值前仔细确认充值金额及支付方式。
				若因网络问题、支付系统故障或其他不可抗力因素导致充值失败，请您及时联系我们的客服人员，我们将为您核实并协助解决问题。
				2.请勿使用非法手段或漏洞进行充值，否则我们将有权冻结您的账户，并追究相关法律责任。
				3.请妥善保管您的账户信息及支付密码，避免因泄露导致账户被盗用或资金损失。
				4.本平台不支持任何形式的代充或刷单行为，如有发现，将对相关账户进行封禁处理。</text>
		</view>
		<view class="ymBbottom"></view>
	</view>
</template>

<script>
	// import voucher_center_ from "./voucher_center_.js";
	// export default voucher_center_;
	export default {
		data() {
			return {
				money: '',
				value: '',
				huodong_id: '',
				map: {
					text: 'name',
					value: 'id'
				},
				huodong: []
			}
		},
		onLoad() {
			this.hudong()
		},
		methods: {
			nom(e){
		//正则表达试
			
						
						  // 必须在nextTick中
						    this.$nextTick(() => {
						        this.money= event.target.value.match(/^\d*(\.?\d{0,2})/g)[0]
						    })
			},
			change(e) {
				console.log(e, 'ee')
				if(e.detail == []){
					this.huodong_id = ''
				}else{
					this.huodong_id = e.detail.value.join("")
				}
			},
			hudong() {
				this.$http.getRechangePre({
				}).then((result) => {
					console.log(result, 'this.huodong ')
					this.huodong = result.data.huodong_list
				}).catch(err => {

				});
			},
			btSubmit_21_click() {
				const huodong = this.huodong_id
				const money = this.money
				if (huodong !== '' && money !== '') {
					console.log(huodong,money,'moneymoney')
				      console.log("警告：huodong 和 money 不能同时赋值，将优先使用 huodong 的值");
					  return
				} 
				var that = this;	
				this.$http.getRechangeSubmit({
					huodong_id: this.huodong_id,
					money: this.money
				}).then((result) => {
					uni.showToast({
						title:result.info,
						icon: 'none'
					});
					console.log('111',result.status);
					if(result.status == 1){
						// setTimeout(()=>{
						// 	uni.navigateBack({
						// 	    delta: 1 // 返回上一页
						// 	});
						// },1000)
						console.log('222',result.data.order_id);
						let order_id = result.data.order_id; 
						that.wxpay(order_id);
					}
				
				}).catch(err => {

				});
			},
			wxpay(order_id){
				
				this.$http.wxPay({
					order_id: order_id
				}).then((result) => {
					uni.showToast({
						title:result.info,
						icon: 'none'
					});
					if(result.status == 1){
						var order = result.data;
						console.log(order)
						uni.requestPayment({
							timeStamp: order.timeStamp,
							nonceStr: order.nonceStr,
							package: order.package,
							signType: 'MD5',
							paySign: order.paySign,
							success: function(res) {
								
								setTimeout(() => {
									uni.hideLoading()
									uni.showModal({
										title:'提示',
										content:'支付成功',
										showCancel:false,
										success: (res) => {
											if (res.confirm) {
												setTimeout(()=>{
													uni.navigateBack({
													    delta: 1 // 返回上一页
													});
												},1000)
											} 
										}
									})
								}, 1000);
								
							},
							fail: function(res) {
								uni.showToast({
									title: '支付未成功',
									icon: 'none',
									duration: 3000
								})
							}
						})
					}else{
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						});
					}
				
				}).catch(err => {
				
				});
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	// @import url("/animate.min.css");
	html,
	body,
	#app {
		height: 100%;
		width: 100%;
	}

	.YmContent {
		height: 100%;
		width: 100%;
	}

	uni-page-body,
	#app {
		height: 100%;
	}

	button::after {
		border: none;
		width: auto;
	}

	input {
		outline: none;
		border: none;
		list-style: none;
		width: auto;
	}

	.list_item {
		float: left;
	}

	.ym_hide {
		display: none;
	}

	.ym_show {
		display: block;
	}

	.slide-image {
		width: 100%;
		height: 100%;
	}

	.list_horizontal {
		width: auto;
		display: inline-block;
	}

	.voucher_center__1 {
		white-space: normal;
		width: 749upx;
		height: 1510upx;
		padding: 0upx;
		clear: both;
		float: left;
		border-radius: 0upx;
		font-size: 8upx;
	}

	.voucher_center__1 .voucher_center__47 {
		white-space: normal;
		width: 181upx;
		height: 34upx;
		padding: 0upx;
		clear: both;
		margin-top: 29upx;
		margin-left: 34upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 34upx;
		line-height: 34upx;
	}

	.voucher_center__1 .voucher_center__48 {
		white-space: normal;
		width: 647upx;
		height: 44upx;
		padding: 0upx;
		clear: both;
		margin-top: 68upx;
		margin-left: 34upx;
		float: left;
		border-radius: 0upx;
		font-size: 43upx;
		line-height: 44upx;
	}

	.voucher_center__1 .voucher_center__48 .voucher_center__49 {
		white-space: normal;
		width: auto;
		height: 44upx;
		padding: 0upx;
		margin-top: 0upx;
		margin-left: 0upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 43upx;
		line-height: 44upx;
	}

	.voucher_center__1 .voucher_center__48 .money {
		white-space: normal;
		width: auto;
		height: 44upx;
		min-height: 44upx;
		padding: 0upx;
		margin-top: 0upx;
		margin-left: 25upx;
		float: left;
		border-radius: 0upx;
		color: #c8c8c8;
		font-size: 43upx;
		line-height: 43upx;
	}

	.voucher_center__1 .payType {
		white-space: normal;
		width: 683upx;
		height: 50upx;
		padding: 0upx;
		clear: both;
		margin-top: 102upx;
		margin-left: 33upx;
		float: left;
		border-radius: 0upx;
		font-size: 49upx;
		line-height: 50upx;
	}

	.voucher_center__1 .payType .voucher_center__55 {
		white-space: normal;
		width: 46upx;
		height: 47upx;
		padding: 0upx;
		margin-top: 3upx;
		margin-left: 2upx;
		float: left;
		border-radius: 0upx;
		font-size: 48upx;
		line-height: 47upx;
	}

	.voucher_center__1 .payType .voucher_center__56 {
		white-space: normal;
		width: 61upx;
		height: 28upx;
		padding: 0upx;
		margin-top: 11upx;
		margin-left: 23upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 27upx;
		line-height: 28upx;
	}

	.voucher_center__1 .payType .voucher_center__57 {
		white-space: normal;
		width: 43upx;
		height: 44upx;
		padding: 0upx;
		margin-top: 2upx;
		margin-left: 4upx;
		float: left;
		border-radius: 0upx;
		font-size: 43upx;
		line-height: 44upx;
	}

	.voucher_center__1 .payType .voucher_center__58 {
		white-space: normal;
		width: 47upx;
		height: 47upx;
		padding: 0upx;
		margin-top: 3upx;
		margin-left: 105upx;
		float: left;
		border-radius: 0upx;
		font-size: 49upx;
		line-height: 47upx;
	}

	.voucher_center__1 .payType .voucher_center__59 {
		white-space: normal;
		width: 81upx;
		height: 29upx;
		padding: 0upx;
		margin-top: 11upx;
		margin-left: 22upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 27upx;
		line-height: 29upx;
	}

	.voucher_center__1 .payType .voucher_center__60 {
		white-space: normal;
		width: 43upx;
		height: 43upx;
		padding: 0upx;
		margin-top: 3upx;
		margin-left: 11upx;
		float: left;
		border-radius: 0upx;
		font-size: 42upx;
		line-height: 43upx;
	}

	.voucher_center__1 .btSubmit {
		white-space: normal;
		width: 679upx;
		height: 90upx;
		padding: 0upx;
		clear: both;
		margin-top: 65upx;
		margin-left: 36upx;
		float: left;
		background-color: #78C0F9;
		text-align: center;
		justify-content: center;
		border-radius: 10upx;
		cursor: pointer;
		color: #ffffff;
		font-size: 27upx;
		line-height: 90upx;
	}

	.voucher_center__1 .voucher_center__22 {
		white-space: normal;
		width: 187upx;
		height: 34upx;
		padding: 0upx;
		clear: both;
		margin-top: 76upx;
		margin-left: 36upx;
		float: left;
		border-radius: 0upx;
		color: #646464;
		font-size: 31upx;
		line-height: 34upx;
	}

	.voucher_center__1 .voucher_center__23 {
		white-space: normal;
		width: 677upx;
		height: 365upx;
		padding: 0upx;
		clear: both;
		margin-top: 32upx;
		margin-left: 36upx;
		float: left;
		border-radius: 0upx;
		color: #c8c8c8;
		font-size: 27upx;
		line-height: 30upx;
	}




	// @import './voucher_center_.scss'
</style>